<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>网签线下合同审核系统</title>
    <link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/default/easyui.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/icon.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/color.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/easyui/demo/demo.css}">
    <script type="text/javascript" th:src="@{/easyui/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/easyui/jquery.easyui.min.js}"></script>
    <script type="text/javascript" th:src="@{/easyui/locale/easyui-lang-zh_CN.js}"></script>
    <style type="text/css">
        #fm{
            margin:0;
            padding:10px 30px;
        }
        .ftitle{
            font-size:14px;
            font-weight:bold;
            padding:5px 0;
            margin-bottom:10px;
            border-bottom:1px solid #ccc;
        }
        .fitem{
            margin-bottom:5px;
        }
        .fitem label{
            display:inline-block;
            width:150px;
        }
        .fitem input{
            width:250px;
        }
    </style>
</head>

<body style="width:100%;height:100%;padding: 0px">
<table id="dg" title="审核列表" class="easyui-datagrid" style="width:100%;height:100%"
       pagination="true"
       striped="true"
       singleSelect="true"
       toolbar="#toolbar"
       url="getOrders?origin=1"
       rownumbers="true"
       fitColumns="true"
       fit="true"
       loadMsg="正在查询...">

    <thead>
    <tr>
        <th field="id" width="4%" >订单序号</th>
        <th field="orderNum" width="10%">委托收购协议号</th>
        <th field="createTime" width="8%">签订日期</th>
        <th field="status" width="5%" >审核状态</th>
        <th field="companyName" width="13%">甲方</th>
        <th field="supplierId" width="4%">供货人序号</th>
        <th field="supplierName" width="5%">供货人姓名</th>
        <th field="supplierIdNum" width="10%">供货人身份证号</th>
        <th field="bankName" width="4%" data-options="editor:'text'">开户行</th>
        <th field="branchBankName" width="6%" data-options="editor:'text'">支行</th>
        <th field="bankNum" width="10%">银行卡号</th>
        <th field="itemName" width="4%">品名</th>
        <th field="price" width="4%">价格</th>
        <th field="weight" width="4%">重量</th>
        <th field="startDate" width="7%">合同生效日期</th>
        <th field="endDate" width="7%">合同失效日期</th>
    </tr>
    </thead>
</table>

<!--分页-->
<!--<div id="pp" style="background:#efefef;border:1px solid #ccc;"></div>-->


<div id="toolbar">
<!--    <a  href="#" class="easyui-linkbutton" iconCls="icon-ok" plain="true" onclick="checkPass()">审核通过</a>-->
<!--    <a  href="#" class="easyui-linkbutton" iconCls="icon-no" plain="true" onclick="checkNotPass()">审核不通过</a>-->
    <a  href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addInput()">新增合同</a>
    <a  href="#" class="easyui-linkbutton" iconCls="icon-cancel" plain="true" onclick="checkDelete()">删除合同</a>
    <a  href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="reload()">刷新合同</a>
    <a  href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="update()">修改合同</a>
    <a  href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="uploadStamp()">上传pdf文件</a>
    <a  href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="openPDF()">查看合同</a>
    <a  href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="downloadContract()">下载选中的合同</a>

    <form style="width: 100%">
        <label>供应商:</label>
        <select class="easyui-combobox" name="companySearch" id="companySearch"
                style="width:250px"
                data-options="valueField:'code',textField:'name',
                            url:'../../../hetong/web/getCompany',
                            editable:true,model:'local'">
        </select>
        <label>货物:</label>
        <select class="easyui-combobox" name="itemSearch" id="itemSearch" style="width:100px">
            <option></option>
            <option>废纸</option>
            <option>废钢</option>
        </select>
        <label>审核状态:</label>
        <select class="easyui-combobox" name="statusSearch" id="statusSearch"
                style="width:100px">
        </select>
        <input id="fuzzySearch" class="easyui-textbox" style="width:250px" prompt="请输入关键字">
        <a  href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="searchInfo()">搜索</a>
    </form>
</div>

<!--确认框-->
<div id="checkPass" class="easyui-window" style="width:380px;padding:10px 40px" closed="true">
    <div>您确认要通过审核吗?</div>
    <div data-options="region:'south',border:false" style="text-align:center;padding:5px 0 0;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="pass()" style="width:80px" handler>确认</a>
        <a class="easyui-linkbutton" data-options="iconCls:'icon-no'" href="javascript:void(0)" onclick="closePass()" style="width:80px">取消</a>
    </div>
</div>

<div id="checkNotPass" class="easyui-window" style="width:380px;padding:10px 40px" closed="true">
    <div>您确认要不通过审核吗?</div>
    <div data-options="region:'south',border:false" style="text-align:center;padding:5px 0 0;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="notPass()" style="width:80px" handler>确认</a>
        <a class="easyui-linkbutton" data-options="iconCls:'icon-no'" href="javascript:void(0)" onclick="closeNotPass()" style="width:80px">取消</a>
    </div>
</div>

<div id="checkDelete" class="easyui-window" style="width:380px;padding:10px 40px" closed="true">
    <div>您确认要删除吗?</div>
    <div data-options="region:'south',border:false" style="text-align:center;padding:5px 0 0;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="deleteOrder()" style="width:80px" handler>确认</a>
        <a class="easyui-linkbutton" data-options="iconCls:'icon-no'" href="javascript:void(0)" onclick="closeDelete()" style="width:80px">取消</a>
    </div>
</div>


<!--添加记录窗口-->
<div id="addInput" class="easyui-dialog" style="width:600px;height:400px;padding:10px 20px"
     closed="true" buttons="#dlg-buttons">
    <div class="ftitle">合同信息</div>
    <form id="fm" method="post" novalidate>
        <div class="fitem">
            <label>委托收购协议号:</label>
            <input id="orderCode" class="easyui-textbox" required="true">
        </div>
        <div class="fitem">
<!--            <label>签订日期:</label>-->
<!--            <input id="date" class="easyui-textbox" required="true">-->
            <label>签订日期:</label>
            <input id="date" style="width:250px" name="createDate" type="text" class="easyui-datebox" required="required">
        </div>
        <div class="fitem">
            <label>品名:</label>
            <input id="itemName" class="easyui-textbox" required="true">
        </div>
        <div class="fitem">
            <label>价格:</label>
            <input id="price" class="easyui-textbox" >
        </div>
        <div class="fitem">
            <label>重量(吨):</label>
            <input id="weight" class="easyui-textbox" >
        </div>
<!--        <div class="fitem">-->
<!--            <label>审核状态:</label>-->
<!--&lt;!&ndash;            <input id="status" class="easyui-textbox" required="true">&ndash;&gt;-->
<!--            <select class="easyui-combobox" name="status" id="status"-->
<!--                    style="width:250px" required="required" value="0">-->
<!--            </select>-->
<!--        </div>-->
        <div class="fitem">
            <label>审核状态:</label>
            <select class="easyui-combobox" name="status1" id="status1"
                    style="width:250px"
                    data-options="valueField:'code',textField:'status',
                            url:'../../../hetong/web/getContractStatusNew',
                            editable:false,
                            prompt:'请选择状态'" required="required">
            </select>
        </div>
        <div class="fitem">
            <label>供应商:</label>  <!--下面的ID与页面工具栏的重复了，故改成companyCode1-->
            <select class="easyui-combobox" name="companyCode" id="companyCode1"
                    style="width:250px"
                    data-options="valueField:'code',textField:'name',
                            url:'../../../hetong/web/getCompany',
                            editable:false,
                            prompt:'请选择供应商'" required="required">
            </select>
        </div>
        <div class="fitem">
            <label>供货人身份证号:</label>
            <select id="supplierIdNum" class="easyui-combobox" data-options="valueField:'code',textField:'name',
                            url:'../../../hetong/web/getSuppliersIdNum',
                            editable:true,
                            prompt:'请输入身份证号'" required="required"
                    buttonAlign="right" buttonText="补全数据" onClickButton="getInfo()" style="width:250px"></select>
        </div>
        <div class="fitem">
            <label>供货人姓名:</label>
            <input id="supplierName" class="easyui-textbox" required="true">
        </div>
        <div class="fitem">
            <label>供货人手机号:</label>
            <input id="phone" class="easyui-textbox" required="true">
        </div>
        <div class="fitem">
            <label>供货人地址:</label>
            <input id="supplierHomeAddress" class="easyui-textbox" required="true">
        </div>
        <div class="fitem">
            <label>开户行:</label>
            <input id="bankName" class="easyui-textbox" required="true">
        </div>
        <div class="fitem">
            <label>支行:</label>
            <input id="branchBankName" class="easyui-textbox" required="true">
        </div>
        <div class="fitem">
            <label>银行卡号:</label>
            <input id="bankNum" class="easyui-textbox" required="true">
        </div>
        <div class="fitem">
            <label>合同生效日期:</label>
            <input id="startDate" style="width:250px" name="createDate" type="text" class="easyui-datebox" required="required">
        </div>
        <div class="fitem">
            <label>合同失效日期:</label>
            <input id="endDate" style="width:250px" name="createDate" type="text" class="easyui-datebox" required="required">
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveEqument()" style="width:120px">保存</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#addInput').dialog('close')" style="width:120px">取消</a>
</div>


<!--文件上传-->
<div id="uploadStamp" class="easyui-window" style="width:380px;padding:10px 40px" closed="true">
    <form id="stamp" method="post" enctype="multipart/form-data">
        <table border="0" style="margin-top:4px;" width="100%" align="center">
            <tr>
                <td>
                    <input class="easyui-filebox" name="upload" data-options="buttonText:'选择文件',prompt:'文件上传'" style="width:100%"></input>
                </td>
            </tr>
        </table>
    </form>

    <div data-options="region:'south',border:false" style="text-align:center;padding:5px 0 0;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="uploadonline('#stamp');" style="width:80px">上传</a>
    </div>
</div>



</body>

<script type="text/javascript">

    var model=1;

    //默认选择
    $("#statusSearch").combobox({
        url: "../../../hetong/web/getContractStatus", //获取后台动作方法返回的json数据
        valueField: 'code',
        textField: 'status',
        panelHeight: "auto",
        editable: false, //不允许手动输入
        // onLoadSuccess: function () { //数据加载完毕事件
        //     $('#statusSearch').combobox('select', '全部');
        // }
    });


    //新增合同的状态选择
    $("#status").combobox({
        url: "../../../hetong/web/getContractStatusNew", //获取后台动作方法返回的json数据
        valueField: 'code',
        textField: 'status',
        panelHeight: "auto",
        editable: false, //不允许手动输入
        onLoadSuccess: function (data) {  //当成功加载数据后所引发的事件，data参数为 combobox中加载的值 以一个json类型的数组表示
            $('#status').combobox('setValue', data[0].id);//设置combobox中的首选项被选中
        }
    });

    //供货人模糊搜索
    $("#supplierIdNum").textbox({onClickButton:function(){
            var supplierIdNum=document.getElementById("supplierIdNum").value;
            $.ajax({
                url:"../../../hetong/web/getInfo?idNum="+supplierIdNum,
                type:"post",
                success:function(result){
                    if(result.status === 200)
                    {
                        $("#supplierName").textbox("setValue",result.data.name);
                        $("#bankNum").textbox("setValue",result.data.bankNum);
                        $("#phone").textbox("setValue",result.data.phoneNum);
                        $("#bankName").textbox("setValue",result.data.bankName);
                        $("#branchBankName").textbox("setValue",result.data.branchBankName);
                        $("#supplierHomeAddress").textbox("setValue",result.data.homeAddress);
                    }
                    else {
                        alert("没有找到该供货人,请确认身份证号或者新建供货人");
                    }
                }
            });
        }})

    //下载合同
    function downloadContract() {
        var row = $('#dg').datagrid('getSelected');
        var orderId=row.id;
        if (row){
            var url="../../../hetong/download?orderId="+orderId;
            window.open(url);
        }
    }

    //盖章
    function uploadStamp() {
        var row = $('#dg').datagrid('getSelected');
        var template=row.templateId;
        if(row)
        {
            if(row.status!=="待盖章"&&template!=null)
            {
                alert("状态为待盖章的才可以上传盖章文件");
            }else
            {
                $('#uploadStamp').window('open').dialog('setTitle','盖章文件上传');
            }
        }
        else
        {
            alert("请选择合同");
        }

    }

    function uploadonline(id) {
        var row = $('#dg').datagrid('getSelected');
        var orderId=row.id;
        var template=row.templateId;

        if(row.status!=="待盖章"&&template!=null)
        {
            alert("状态为待盖章的才可以上传盖章文件");
        }
        else
        {
            var add="../../../hetong/web/uploadContractFile?id="+orderId;
            $(id).form('submit',{
                url: add,
                onSubmit: function(){
                },
                success: function(result){
                    reload();
                    var result = eval('('+result+')');
                    if (result.status==200){
                        $('#uploadonlineinfo').window('close');
                        $('#dg2').datagrid('reload');
                        $.messager.show({
                            title: 'Success',
                            msg: '上传成功'
                        });
                        $('#uploadStamp').dialog('close');
                    } else {
                        $.messager.show({
                            title: 'Error',
                            msg: result.message
                        });
                    }
                }
            });
        }
    }

    //上传PDF合同文件


    // function stamp() {
    //     var row = $('#dg').datagrid('getSelected');
    //     if (row){
    //         var id=row.id;
    //         $.ajax({
    //             url:"contract/stamp",
    //             type:"post",
    //             data:{
    //                 id:id,
    //             },
    //             datatype:"josn",
    //             success:function(result){
    //                 $('#dg').datagrid('reload');
    //             }
    //         });
    //     }
    // }

    //通过审核
    function checkPass()
    {
        // $('#checkPass').window('open').dialog('setTitle','操作确认');
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $.messager.confirm('提示', '您确定要通过审核吗?', function(r) {
                if (r) {
                    var id=row.id;
                    if(row.status!=="待审核")
                    {
                        alert("状态为待审核的才可以通过");
                    }
                    $.ajax({
                        url:"../../../hetong/web/passOrder",
                        type:"post",
                        data:{
                            id:id,
                        },
                        datatype:"josn",
                        success:function(result){
                            $('#dg').datagrid('reload');
                            $('#checkPass').dialog('close');
                            alert(result.data);
                        }
                    });
                }
            });
        }
    }

    function closePass() {
        $('#checkPass').dialog('close');
    }

    function pass() {
        var row = $('#dg').datagrid('getSelected');
        if (row){
            var id=row.id;
            if(row.status!=="已提交")
            {
                alert("状态为已提交的才可以通过");
            }
            $.ajax({
                url:"../../../hetong/web/passOrder",
                type:"post",
                data:{
                    id:id,
                },
                datatype:"josn",
                success:function(result){
                    $('#dg').datagrid('reload');
                    $('#checkPass').dialog('close');
                }
            });
        }
    }

    //不通过审核
    function checkNotPass()
    {
        // $('#checkNotPass').window('open').dialog('setTitle','操作确认');
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $.messager.confirm('提示', '您确定要不通过审核吗?', function(r) {
                if (r) {
                    var id=row.id;
                    $.ajax({
                        url:"../../../hetong/web/notPassOrder",
                        type:"post",
                        data:{
                            id:id,
                        },
                        datatype:"josn",
                        success:function(result){
                            $('#dg').datagrid('reload');
                            $('#checkNotPass').dialog('close');
                        }
                    });
                }
            });
        }
    }

    function closeNotPass() {
        $('#checkNotPass').dialog('close');
    }

    function notPass() {
        var row = $('#dg').datagrid('getSelected');
        if (row){
            var id=row.id;
            $.ajax({
                url:"../../../hetong/web/notPassOrder",
                type:"post",
                data:{
                    id:id,
                },
                datatype:"josn",
                success:function(result){
                    $('#dg').datagrid('reload');
                    $('#checkNotPass').dialog('close');
                }
            });
        }
    }

    //删除记录
    function checkDelete()
    {
        // $('#checkDelete').window('open').dialog('setTitle','操作确认');
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $.messager.confirm('提示', '您确定要删除该记录吗?', function(r) {
                if (r) {
                    var id=row.id;
                    $.ajax({
                        url:"../../../hetong/web/deleteOrder",
                        type:"post",
                        data:{
                            id:id,
                        },
                        datatype:"josn",
                        success:function(result){
                            $('#dg').datagrid('reload');
                            $('#checkDelete').dialog('close');
                        }
                    });
                }
            });
        }
    }

    function closeDelete() {
        $('#checkDelete').dialog('close');
    }

    function deleteOrder() {
        var row = $('#dg').datagrid('getSelected');
        if (row){
            var id=row.id;
            $.ajax({
                url:"../../../hetong/web/deleteOrder",
                type:"post",
                data:{
                    id:id,
                },
                datatype:"josn",
                success:function(result){
                    $('#dg').datagrid('reload');
                    $('#checkDelete').dialog('close');
                }
            });
        }
    }
    //刷新
    function reload() {
        $('#dg').datagrid('reload');
    }

    //更新数据
    function update() {
        this.model=2;
        $('#addInput').dialog('open').dialog('center').dialog('setTitle', '修改');
        $('#fm').form('clear');
        var row = $('#dg').datagrid('getSelected');
        if(row)
        {
            $.ajax({
                url:"../../../hetong/web/getOrderInfo?id="+row.id,
                type:"post",
                success:function(result){
                    if(result.status===200)
                    {
                        $('#orderCode').textbox('setValue',result.data.orderNum);
                        $('#itemName').textbox('setValue',result.data.itemName);
                        $('#price').textbox('setValue',result.data.price);
                        $('#weight').textbox('setValue',result.data.weight);
                        $('#status1').combobox('select',result.data.status);
                        $('#companyCode1').combobox('select',result.data.companyName);
                        $('#supplierIdNum').textbox('setValue',result.data.supplierIdNum);
                        $('#supplierName').textbox('setValue',result.data.supplierName);
                        $('#phone').textbox('setValue',result.data.supplierPhone);
                        $('#supplierHomeAddress').textbox('setValue',result.data.supplierHomeAddress);
                        $('#bankName').textbox('setValue',result.data.bankName);
                        $('#branchBankName').textbox('setValue',result.data.branchBankName);
                        $('#bankNum').textbox('setValue',result.data.bankNum);
                        $('#date').textbox('setValue',result.data.createTime);
                        $('#startDate').textbox('setValue',result.data.startDate);
                        $('#endDate').textbox('setValue',result.data.endDate);
                    }
                    else
                    {
                        $('#dg').datagrid('loaded');
                        alert(result.message);
                    }

                }
            });
        }
        else
        {
            alert("请选择一条数据");
        }
    }


    //查看合同
    function openPDF()
    {
        var row = $('#dg').datagrid('getSelected');
        var orderId=row.id;
        if (row){
            var url="../../../hetong/download?orderId="+orderId+"&model=0";
            window.open(url);
        }
    }

    //弹出新建窗口
    function addInput() {
        this.model=1;
        $('#addInput').dialog('open').dialog('center').dialog('setTitle', '新建');
        $('#fm').form('clear');
    }

    function saveEqument() {

        //判定必填项是否填完了
            if(model===1)
            {
                if($("#fm").form('validate'))
                {
                    var orderCode=document.getElementById("orderCode").value;
                    var date=document.getElementById("date").value;
                    var itemName=document.getElementById("itemName").value;
                    var price=document.getElementById("price").value;
                    var weight=document.getElementById("weight").value;
                    var status=$("#status1").combobox("getValue");
                    var companyName=$("#companyCode1").combobox("getText");
                    var supplierName=document.getElementById("supplierName").value;
                    var supplierIdNum=document.getElementById("supplierIdNum").value;
                    var supplierHomeAddress=document.getElementById("supplierHomeAddress").value;
                    var bankName=document.getElementById("bankName").value;
                    var branchBankName=document.getElementById("branchBankName").value;
                    var bankNum=document.getElementById("bankNum").value;
                    var startDate=document.getElementById("startDate").value;
                    var endDate=document.getElementById("endDate").value;
                    var phone=document.getElementById("phone").value;
                    var formData = new FormData();
                    formData.append("item",itemName);
                    formData.append("company",companyName);
                    formData.append("idNum",supplierIdNum);

                    if(status==="1")
                    {
                        status="0";
                    }

                    $.ajax({
                        url:"../../../hetong/contract/onlyOne",
                        type:"post",
                        data:formData,
                        cache: false,
                        processData: false,
                        contentType: false,
                        success:function(result){
                            if(result.data===true)
                            {
                                $.ajax({
                                    url:"../../../hetong/web/addOrderByWeb",
                                    type:"post",
                                    data:JSON.stringify(
                                        {
                                            orderCode:orderCode,
                                            date:date,
                                            itemName:itemName,
                                            price:price,
                                            weight:weight,
                                            status:status,
                                            companyName:companyName,
                                            supplierName:supplierName,
                                            supplierIdNum:supplierIdNum,
                                            supplierHomeAddress:supplierHomeAddress,
                                            bankName:bankName,
                                            branchBankName:branchBankName,
                                            bankNum:bankNum,
                                            startDate:startDate,
                                            endDate:endDate,
                                            phone:phone,
                                        }
                                    ),
                                    datatype:"josn",
                                    contentType:"application/json",
                                    success:function(result){
                                        if(result.status===200)
                                        {
                                            alert("添加成功");
                                        }
                                        else
                                        {
                                            alert(result.message);
                                        }
                                        $('#dg').datagrid('reload');
                                    }
                                });
                            }
                            else
                            {
                                alert("出现重复合同,该供货人存在着另一个品名和公司与此相同的合同");
                            }
                            $('#dg').datagrid('reload');
                        }
                    })
                }
                else
                {
                    alert("请填完所有必填空");
                }

            }
            else if(model===2)
            {
                //判定必填项是否填完了
                if($("#fm").form('validate')){
                    var row = $('#dg').datagrid('getSelected');
                    var id=row.id;
                    var supplierId=row.supplierId;
                    var orderCode=document.getElementById("orderCode").value;
                    var date=document.getElementById("date").value;
                    var itemName=document.getElementById("itemName").value;
                    var price=document.getElementById("price").value;
                    var weight=document.getElementById("weight").value;
                    var status=$("#status1").combobox("getValue");
                    var companyName=$("#companyCode1").combobox("getText");
                    var supplierName=document.getElementById("supplierName").value;
                    var supplierIdNum=document.getElementById("supplierIdNum").value;
                    var supplierHomeAddress=document.getElementById("supplierHomeAddress").value;
                    var bankName=document.getElementById("bankName").value;
                    var branchBankName=document.getElementById("branchBankName").value;
                    var bankNum=document.getElementById("bankNum").value;
                    var startDate=document.getElementById("startDate").value;
                    var endDate=document.getElementById("endDate").value;
                    var phone=document.getElementById("phone").value;
                    var formData = new FormData();
                    formData.append("item",itemName);
                    formData.append("company",companyName);
                    formData.append("idNum",supplierIdNum);

                    if(status==="1")
                    {
                        status="0";
                    }
                    $.ajax({
                        url:"../../../hetong/web/update",
                        type:"post",
                        data:JSON.stringify(
                            {
                                id:id,
                                orderCode:orderCode,
                                createTime:date,
                                itemName:itemName,
                                price:price,
                                weight:weight,
                                status:status,
                                companyName:companyName,
                                supplierId:supplierId,
                                supplierName:supplierName,
                                supplierIdNum:supplierIdNum,
                                supplierPhone:phone,
                                supplierHomeAddress:supplierHomeAddress,
                                bankName:bankName,
                                branchBankName:branchBankName,
                                bankNum:bankNum,
                                startDate:startDate,
                                endDate:endDate,
                                phone:phone,
                                origin:1,
                            }
                        ),
                        datatype:"josn",
                        contentType:"application/json",
                        success:function(result){
                            if(result.status===200)
                            {
                                alert("修改成功");
                            }
                            else
                            {
                                alert(result.message);
                            }
                            $('#dg').datagrid('reload');
                        }
                    });
                }
                else
                {
                    alert("请填完所有必填空");
                }
            }

    }

    function updateEqument()
    {
        //判定必填项是否填完了
        if($("#fm").form('validate')){
            var row = $('#dg').datagrid('getSelected');
            var id=row.id;
            var supplierId=row.supplierId;
            var orderCode=document.getElementById("orderCode").value;
            var date=document.getElementById("date").value;
            var itemName=document.getElementById("itemName").value;
            var price=document.getElementById("price").value;
            var weight=document.getElementById("weight").value;
            var status=$("#status1").combobox("getValue");
            var companyName=$("#companyCode1").combobox("getText");
            var supplierName=document.getElementById("supplierName").value;
            var supplierIdNum=document.getElementById("supplierIdNum").value;
            var supplierHomeAddress=document.getElementById("supplierHomeAddress").value;
            var bankName=document.getElementById("bankName").value;
            var branchBankName=document.getElementById("branchBankName").value;
            var bankNum=document.getElementById("bankNum").value;
            var startDate=document.getElementById("startDate").value;
            var endDate=document.getElementById("endDate").value;
            var phone=document.getElementById("phone").value;
            var formData = new FormData();
            formData.append("item",itemName);
            formData.append("company",companyName);
            formData.append("idNum",supplierIdNum);

            if(status==="1")
            {
                status="0";
            }
            $.ajax({
                url:"../../../hetong/web/update",
                type:"post",
                data:JSON.stringify(
                    {
                        id:id,
                        orderCode:orderCode,
                        createTime:date,
                        itemName:itemName,
                        price:price,
                        weight:weight,
                        status:status,
                        companyName:companyName,
                        supplierId:supplierId,
                        supplierName:supplierName,
                        supplierIdNum:supplierIdNum,
                        supplierPhone:phone,
                        supplierHomeAddress:supplierHomeAddress,
                        bankName:bankName,
                        branchBankName:branchBankName,
                        bankNum:bankNum,
                        startDate:startDate,
                        endDate:endDate,
                        phone:phone,
                        origin:1,
                    }
                ),
                datatype:"josn",
                contentType:"application/json",
                success:function(result){
                    if(result.status===200)
                    {
                        alert("修改成功");
                    }
                    else
                    {
                        alert(result.message);
                    }
                    $('#dg').datagrid('reload');
                }
            });
        }
        else
        {
            alert("请填完所有必填空");
        }
    }


    //搜索
    function searchInfo() {
        var company=$("#companySearch").combobox("getText");
        var status=$("#statusSearch").combobox("getText");
        var item=$("#itemSearch").combobox("getText");
        var info=document.getElementById("fuzzySearch").value;
        var page = $("#dg").datagrid('options').pageNumber;
        var rows = $("#dg").datagrid('options').pageSize;
        var options = $('#dg').datagrid('getPager').data("pagination").options;
        //总记录数
        var total = options.total;
        $('#dg').datagrid('loading');
        $.ajax({
            url:"../../../hetong/web/searchOrder",
            type:"post",
            data:JSON.stringify(
                {
                    total:total,
                    page:page,
                    rows:rows,
                    status:status,
                    item:item,
                    company:company,
                    info:info,
                    origin:1,
                }
            ),
            datatype:"josn",
            contentType:"application/json",
            success:function(result){
                if(result.status===200)
                {
                    $('#dg').datagrid('loaded');
                    $('#dg').datagrid('loadData',result.data);
                }
                else
                {
                    $('#dg').datagrid('loaded');
                    alert(result.message);
                }

            }
        });

    }

    //模糊搜索
    function searchFuzzyOrder() {
        var info=document.getElementById("fuzzySearch").value;
        var page = $("#dg").datagrid('options').pageNumber;
        var rows = $("#dg").datagrid('options').pageSize;
        var options = $('#dg').datagrid('getPager').data("pagination").options;
        //总记录数
        var total = options.total;
        $('#dg').datagrid('loading');
        $.ajax({
            url:"../../../hetong/web/searchFuzzyOrder?info="+info+'&rows='+rows+'&page='+page,
            type:"post",
            success:function(result){
                if(result.status===200)
                {
                    $('#dg').datagrid('loaded');
                    $('#dg').datagrid('loadData',result.data);
                }
                else
                {
                    $('#dg').datagrid('loaded');
                    alert(result.message);
                }

            }
        });
    }




</script>


<!--表格可编辑-->
<!--<script type="text/javascript">-->
<!--    $.extend($.fn.datagrid.methods, {-->
<!--        editCell: function (jq, param) {-->
<!--            return jq.each(function () {-->
<!--                var opts = $(this).datagrid('options');-->
<!--                var fields = $(this).datagrid('getColumnFields', true).concat($(this).datagrid('getColumnFields'));-->
<!--                for (var i = 0; i < fields.length; i++) {-->
<!--                    var col = $(this).datagrid('getColumnOption', fields[i]);-->
<!--                    col.editor1 = col.editor;-->
<!--                    if (fields[i] != param.field) {-->
<!--                        col.editor = null;-->
<!--                    }-->
<!--                }-->
<!--                $(this).datagrid('beginEdit', param.index);-->
<!--                for (var i = 0; i < fields.length; i++) {-->
<!--                    var col = $(this).datagrid('getColumnOption', fields[i]);-->
<!--                    col.editor = col.editor1;-->
<!--                }-->
<!--            });-->
<!--        }-->
<!--    });-->

<!--    var editIndex = undefined;-->
<!--    function endEditing() {-->
<!--        if (editIndex == undefined) { return true }-->
<!--        if ($('#dg').datagrid('validateRow', editIndex)) {-->
<!--            $('#dg').datagrid('endEdit', editIndex);-->
<!--            editIndex = undefined;-->
<!--            return true;-->
<!--        } else {-->
<!--            return false;-->
<!--        }-->
<!--    }-->


<!--    function onClickCell(index, field) {-->
<!--        if (endEditing()) {-->
<!--            $('#dg').datagrid('selectRow', index)-->
<!--                .datagrid('editCell', { index: index, field: field });-->
<!--            editIndex = index;-->
<!--        }-->
<!--    }-->



<!--</script>-->
</html>